import axios, { AxiosRequestConfig } from 'axios';
import { SelfPromise } from 'src/config/ClassType';

export default class Axios {
    static axiosGet(url: string, config?: AxiosRequestConfig<any>): SelfPromise {
        return new Promise(resolve => {
            axios.get(url, config)
                .then(res => resolve([undefined, res.data]))
                .catch(e => resolve([e, undefined]))
        })
    }

    static axiosPost(url: string, form: any, config?: AxiosRequestConfig<any>): SelfPromise {
        return new Promise(resolve => {
            axios.post(url, form, config)
                .then(res => resolve([undefined, res.data]))
                .catch(e => resolve([e, undefined]))
        })
    }

    static axiosDelete(url: string, config?: AxiosRequestConfig<any>): SelfPromise {
        return new Promise(resolve => {
            axios.delete(url, config)
                .then(res => resolve([undefined, res.data]))
                .catch(e => resolve([e, undefined]))
        })
    }
}